package service.sys;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.BaseMapper;
import com.common.BaseService;
import com.common.Cache;
import com.common.CacheManager;
import com.common.CommonUtil;

import beans.sys.CityRegionBean;
import mapper.sys.CityRegionMapper;

@Service
@Transactional
public class CityRegionServiceImpl<T> extends BaseService<T>{

	@Autowired
	private CityRegionMapper cityRegionMapper;
	
	@Override
	public BaseMapper<T> getMapper() {
		return cityRegionMapper;
	}
	
	public CityRegionBean getByCode(String code){
		return cityRegionMapper.queryById(code);
	}

	public void updateStatus(String isuse, String[] ids) {
		cityRegionMapper.updateStatus(isuse,ids);
	}

	public List<CityRegionBean> findAll() {

		Cache cache = CacheManager.getCacheInfo("area");
		List<CityRegionBean> areaList = null;
		if(cache!=null) areaList = (List<CityRegionBean>)cache.getValue();
		if(areaList==null){
			areaList = cityRegionMapper.findAll();
			cache = new Cache();
			cache.setValue(areaList);
			CacheManager.putCache("area", cache);
		}
		
		return areaList;
	}
}
